package demo3;

public abstract class Animal {
    //姓名、年龄
    public String name;
    int age;
    public Animal(String name,int age) {
        this.name = name;
        this.age = age;
    }
    //吃饭的动作
    public abstract void eat();
}
//由于不是每个动物都能run\swim\fly 故创建接口
interface IFly{
    void fly();
}
interface IRun{
    void run();
}
interface ISwim{
    void swim();
}
//把共性及行为提取后，创建指定的动物类

//狗是动物 具备跑步功能
class Dog extends Animal implements IRun{
    public Dog() {
        super("狗子",8);
    }
    public void eat() {
        System.out.println(this.name+" 正在吃狗粮");
    }
    public void run() {
        System.out.println(this.name+" 正在用四条腿跑步");
    }
}
//青蛙是两栖动物 能跳 能游泳
class Frog extends Animal implements IRun,ISwim{
    public Frog() {
        super("青蛙",2);
    }
    public void eat() {
        System.out.println(this.name+" 正在吃蛙粮");
    }
    public void run() {
        System.out.println(this.name+" 正在用两条腿跳着走");
    }
    public void swim() {
        System.out.println(this.name+" 正在标准蛙泳");
    }
}
//鸭子海陆空都能走
class Duck extends Animal implements IFly,IRun,ISwim{
    public Duck() {
        super("鸭子",4);
    }
    public void eat() {
        System.out.println(this.name+" 正在吃鸭粮");
    }
    public void run() {
        System.out.println(this.name+" 正在屁颠屁颠跑");
    }
    public void swim() {
        System.out.println(this.name+" 正在用鸭掌划水");
    }
    public void fly() {
        System.out.println(this.name+" 正在扑腾翅膀飞");
    }
}

class Test{
    public static void func(Animal animal) {
        animal.eat();
    }
    public static void flying(IFly iFly) {
        iFly.fly();
    }
    public static void running(IRun iRun) {
        iRun.run();
    }
    public static void swimming(ISwim iSwim) {
        iSwim.swim();
    }
    public static void main(String[] args) {
        func(new Dog());
        func(new Duck());
        func(new Frog());
        System.out.println("==============");
        running(new Dog());
        running(new Frog());
        running(new Duck());
        System.out.println("==============");
        swimming(new Duck());
        swimming(new Frog());
        System.out.println("==============");
        flying(new Duck());
    }
}